<?php
class site_k_officeList extends ss_konstrukt_master_component {
	protected $templates;
	protected $structureMapper;
	protected $entryMapper;
	protected $strucure;
	protected $node;
	protected $offices;
	
	public function __construct($ss_settings,site_templatefactory $templates, site_dao_structure_mapper $structureMapper){
		$this->structureMapper=$structureMapper;
		$this->structure=$structureMapper->api_master();
    	$this->templates = $templates;
		$this->settings=$ss_settings;
	}
	
	public function dispatch(){
		$this->offices= $this->injector()->create('site_dao_office_mapper')->master();
		//$this->node=$this->structure->getNodeFromSlug($this->name());
		//$this->document->setTitle("Structure ".$this->node->headline());
		ss_error::log('Office list dispatch');
		//$this->entries=$this->entryMapper->getEntriesByCategorySlug($this->name());
		//ss_error::log($this->node->primary(),'ID');
		return parent::dispatch();
	}
	
	public function getOfficeByConnection($id){
		foreach($this->offices as $obj){
			ss_error::log($obj->structure_item_idstructure_item(),"Matching {$id} to");
			if($obj->structure_item_idstructure_item()==$id) return $obj;
		}
		return false;
	}
  
	protected function map($name){
		return 'site_k_office';
		//if($this->structure->levelHasSlug($this->level(),$name)) return 'site_k_structure';
	}
	
	protected function renderHtml() {
		$entries=array();
		foreach($this->offices as $obj){
			$offices[]=$obj->master();
		}
		ss_error::log('Index render');
    	$smarty = $this->templates->create();
	    $smarty->assign('content', $offices);
		$smarty->register_object('ss_path', $this->settings->server->appath);
	    $smarty->assign('context', $this);
    	return $smarty->fetch("officeList.tpl");
	}
}
?>